Object.defineProperty(exports, "__esModule", {
    value: !0
}), exports.loginPcMethod = exports.gotoVersion = exports.inviteShareConfig = exports.claimConfig = exports.overPayNumModal = exports.overPayNumTip = exports.isOverPayNum = exports.switchCorp = exports.loadContact = exports.formatContact = exports.isManager = exports.MINIAPP_SHOW = exports.VERSION_TEXT = exports.VERSION = exports.TRYOUT_STATUS = exports.JOIN_STATUS = exports.STATUS = exports.CLAIM = exports.GRADE = exports.AUTH = exports.STYLES = exports.ROOT_CAT_NAME = exports.ROOT_CATID = void 0;

var _api = _interopRequireDefault(require("./api")), _util2 = _interopRequireDefault(require("./util")), _cardUtil = _interopRequireDefault(require("./card-util")), _util3 = _interopRequireDefault(require("../public/utils/util")), _apiCode = _interopRequireDefault(require("../public/utils/api-code")), _eventEmitter = _interopRequireDefault(require("../public/utils/event-emitter"));

function _interopRequireDefault(t) {
    return t && t.__esModule ? t : {
        default: t
    };
}

function _slicedToArray(t, e) {
    return _arrayWithHoles(t) || _iterableToArrayLimit(t, e) || _nonIterableRest();
}

function _nonIterableRest() {
    throw new TypeError("Invalid attempt to destructure non-iterable instance");
}

function _iterableToArrayLimit(t, e) {
    var a = [], r = !0, o = !1, i = void 0;
    try {
        for (var n, c = t[Symbol.iterator](); !(r = (n = c.next()).done) && (a.push(n.value), 
        !e || a.length !== e); r = !0) ;
    } catch (t) {
        o = !0, i = t;
    } finally {
        try {
            r || null == c.return || c.return();
        } finally {
            if (o) throw i;
        }
    }
    return a;
}

function _arrayWithHoles(t) {
    if (Array.isArray(t)) return t;
}

var ROOT_CATID = 0;

exports.ROOT_CATID = ROOT_CATID;

var ROOT_CAT_NAME = "根目录";

exports.ROOT_CAT_NAME = ROOT_CAT_NAME;

var STYLES = _cardUtil.default.STYLES;

exports.STYLES = STYLES;

var AUTH = _cardUtil.default.AUTH;

exports.AUTH = AUTH;

var GRADE = _cardUtil.default.GRADE;

exports.GRADE = GRADE;

var CLAIM = {
    FAIL: 0,
    SUCCESS: 1
};

exports.CLAIM = CLAIM;

var STATUS = {
    NORMAL: 1,
    DISMISS: 2
};

exports.STATUS = STATUS;

var JOIN_STATUS = {
    NOT_JOIN: 0,
    JOIN: 1,
    DISMISSION: 2
};

exports.JOIN_STATUS = JOIN_STATUS;

var TRYOUT_STATUS = {
    USE: 1,
    UNUSED: 2,
    EXPIRE: 3
};

exports.TRYOUT_STATUS = TRYOUT_STATUS;

var VERSION = _cardUtil.default.VERSION;

exports.VERSION = VERSION;

var VERSION_TEXT = _cardUtil.default.VERSION_TEXT;

exports.VERSION_TEXT = VERSION_TEXT;

var MINIAPP_SHOW = {
    NORMAL: 0,
    ISEXTERNAL: 1
};

exports.MINIAPP_SHOW = MINIAPP_SHOW;

var isManager = function(t) {
    return t.auth !== AUTH.NORMAL;
};

exports.isManager = isManager;

var formatContact = function(t, e, a) {
    var r = 3 < arguments.length && void 0 !== arguments[3] ? arguments[3] : Math.ceil(Date.now() / 1e3);
    t && t.guid && (t.waitJoin = +t.grade === GRADE.WAIT_JOIN, t.waitJoin && (t.version = VERSION.FREE), 
    t.ischarge = a, _cardUtil.default.handleVersion(r, t), t.total = e, t.expireTime = _util3.default.formatLocalDate(t.expiretime, "Y.M.D"), 
    t.versionInfo = t.isGroup || t.isFeeVer ? VERSION_TEXT[t.version] : VERSION_TEXT[1], 
    _cardUtil.default.formatAuthority(t));
};

exports.formatContact = formatContact;

var defaultData = {
    contact: {},
    site: [],
    total: 0,
    contacttotal: 0
}, emit = function(t) {
    t.timestamp = Date.now(), formatContact(t.contact, t.total, t.ischarge, t.servertime);
    var e = getApp().globalData, a = _util2.default.diff(t, e.contact);
    loadApplyList((e.contact = t).contact), 1 < Object.keys(a).length && _eventEmitter.default.emit("contact.change", t);
}, loadContact = function(t) {
    var e = _cardUtil.default.loadMyCard(), a = _api.default.minicard.contact.view({
        data: {
            isdefault: 1
        },
        at: !0
    }).then(function(t) {
        var e = t.data;
        return t.code === _apiCode.default.SUCCESS ? emit(e) : Promise.reject();
    }).catch(function() {
        return emit(defaultData);
    });
    return Promise.all([ e, a ]).then(t, t);
};

exports.loadContact = loadContact;

var MINE_TABLE_INDEX = 3;

function loadApplyList(t) {
    t && (t.isCreator || t.isAdmin) ? _api.default.minicard.manage.applyjoinlists({
        data: {
            guid: t.guid,
            status: "0"
        }
    }).then(function(t) {
        var e = t.data.list, a = getApp().globalData;
        wx["".concat(e.length ? "show" : "hide", "TabBarRedDot")]({
            index: MINE_TABLE_INDEX
        }), a.applyList = e, _eventEmitter.default.emit("contact.applylist", e);
    }) : (_eventEmitter.default.emit("contact.applylist", []), wx.hideTabBarRedDot({
        index: MINE_TABLE_INDEX
    }));
}

var switchCorp = function(r) {
    return new Promise(function(t, e) {
        var a = getApp().globalData.card;
        return r ? a && a.guid === r ? t() : void _api.default.minicard.contact.changecorpname({
            data: {
                guid: r
            }
        }).then(function() {
            loadContact(), t();
        }, e) : e();
    });
};

exports.switchCorp = switchCorp;

var isOverPayNum = function(t) {
    var e = t.total, a = t.paynum;
    return Number(e) >= Number(a);
};

exports.isOverPayNum = isOverPayNum;

var overPayNumTip = function(t, e) {
    var a = t.version, r = t.paynum, o = VERSION_TEXT[a];
    return Number(a) === VERSION.FREE ? "".concat(o, "企业仅支持").concat(r, "个成员，升级为").concat(VERSION_TEXT[VERSION.FEE], "后可").concat(e) : "当前".concat(o, "仅支持").concat(r, "个成员，升级后可").concat(e);
};

exports.overPayNumTip = overPayNumTip;

var overPayNumModal = function(e) {
    var t, a = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "继续添加";
    if (isOverPayNum(e)) return t = overPayNumTip(e, a), wx.showModal({
        content: t,
        confirmText: "去升级",
        success: function(t) {
            return t.confirm && gotoVersion(e.guid);
        }
    }), !0;
};

exports.overPayNumModal = overPayNumModal;

var claimConfig = function(t) {
    var e = getApp().globalData.tokens || {}, a = e.realname, r = void 0 === a ? "有人" : a, o = e.uid, i = "/pages/contacts/cardview/cardview?realname=".concat(encodeURIComponent(r), "&aid=").concat(t.aid || "", "&cardid=").concat(t.cardid, "&guid=").concat(t.guid, "&fromuid=").concat(o);
    return {
        title: "".concat(r, "邀请您认领名片"),
        imageUrl: "https://img.ibos.cn/common/qyy/card/paimingpian.png",
        path: i
    };
};

exports.claimConfig = claimConfig;

var inviteShareConfig = function(t) {
    var e = t.params, a = t.success, r = t.fail, o = t.complete, i = getApp().globalData, n = i.card, c = i.contact, u = i.tokens.uid, s = c.contact.corpname;
    return e.fromuid = u, e.cardid = n.cardid, e.corpname && (e.from = "agent", s = e.corpname, 
    delete e.corpname), console.log("/pages/contacts/invite/invite?".concat(Object.keys(e).map(function(t) {
        return t + "=" + e[t];
    }).join("&"))), {
        title: "".concat(n.realname, "邀请你加入“").concat(s, "”企业通讯录"),
        imageUrl: "https://img.ibos.cn/common/card/other/invite.png",
        path: "/pages/contacts/invite/invite?".concat(Object.keys(e).map(function(t) {
            return t + "=" + e[t];
        }).join("&")),
        success: a,
        fail: r,
        complete: o
    };
};

exports.inviteShareConfig = inviteShareConfig;

var gotoVersion = function(t) {
    var e = 1 < arguments.length && void 0 !== arguments[1] ? arguments[1] : "", a = 2 < arguments.length ? arguments[2] : void 0, r = getApp().globalData, o = r.contact.contact, i = r.isIOS ? "version" : "upgrade/upgrade";
    o.isGroup ? wx.navigateToMiniProgram({
        appId: "wx0ac42dd945fd158d",
        path: "pages/chat/view/view?source=xmp&mode=create&guid=".concat(t)
    }) : (a && (i = o && o.isFeeVer ? i : "version"), _slicedToArray(getCurrentPages(), 1)[0].$route("/pages/contacts/version/".concat(i, "?guid=").concat(t, "&").concat(e)));
};

exports.gotoVersion = gotoVersion;

var loginPcMethod = function(t, e) {
    return _api.default.site.site.loginpc({
        data: Object.assign({
            scene: t.scene,
            op: "login"
        }, e)
    });
};

exports.loginPcMethod = loginPcMethod;